<template>
  <div class="app-container customer-div">
    <div style="margin-top: 40px">
      <!--搜索-->
      <el-form :inline="true" :model="listQuery" size="mini" label-width="100px">
        <el-form-item label="单据编号：">
          <el-input v-model="listQuery.entrySn"></el-input>
        </el-form-item>
        <el-form-item label="单据日期：" >
          <el-date-picker
                  :default-time="['00:00:00', '23:59:59']"
                  v-model="listQuery.createTime"
                  type="daterange"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="单据类型：">
          <el-select v-model="listQuery.billType"  placeholder="请选择" clearable>
            <el-option
                    key="in"
                    label="入库单"
                    value="buy">
            </el-option>
            <el-option
                    key="out"
                    label="出库单"
                    value="return">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="业务员：">
          <el-select v-model="listQuery.userId" filterable placeholder="请选择" clearable>
            <el-option
                    v-for="item in userOptionList"
                    :key="item.userId"
                    :label="item.userName"
                    :value="item.userId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="报销状态：">
          <el-select v-model="listQuery.isFreightSettled"  placeholder="请选择" clearable>
            <el-option
                    :key="0"
                    label="未报销"
                    :value="0">
            </el-option>
            <el-option
                    :key="1"
                    label="已报销"
                    :value="1">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
                  @click="handleSearchList()"
                  type="primary">
            查询
          </el-button>
        </el-form-item>
      </el-form>
    </div>

    <!--数据列表-->
    <div class="table-container">
      <el-table
              v-loading="listLoading"
              :data="tableData"
              border
              style="width: 100%; margin-top: 20px">
        <el-table-column  label="单据类型" width="100" align="center" prop="billType">
        </el-table-column>
        <el-table-column  label="单据编号" width="150" align="center" prop="entrySn">
        </el-table-column>
        <el-table-column  label="日期" width="100" align="center" prop="createTime">
        </el-table-column>
        <el-table-column  label="供应商名称" width="300" align="center">
          <template slot-scope="scope">
            {{scope.row.supplierName}}
          </template>
        </el-table-column>
        <el-table-column  label="出库类别" width="100" align="center">
          <template slot-scope="scope">
            {{scope.row.entryType}}
          </template>
        </el-table-column>
        <el-table-column
                label="备注"
                width="200">
          <template slot-scope="scope">
            {{scope.row.remark}}
          </template>
        </el-table-column>
        <el-table-column
                label="运费"
                align="center"
                width="100">
          <template slot-scope="scope">
            {{scope.row.freight}}
          </template>
        </el-table-column>
        <el-table-column
                label="司机运费"
                align="center"
                width="100">
          <template slot-scope="scope">
            {{scope.row.driverFreight}}
          </template>
        </el-table-column>
        <el-table-column
                label="报销状态"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.isFreightSettled== 0 ? '未报销' : '已报销'}}
          </template>
        </el-table-column>
        <el-table-column
                label="报销时间"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.freightSettleTime}}
          </template>
        </el-table-column>
        <el-table-column
                label="业务员"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.userName}}
          </template>
        </el-table-column>
        <el-table-column
                align="center"
                label="操作"
                width="100">
          <template slot-scope="scope">
            <el-button type="text" @click="toDetail(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination-container">
      <el-pagination
              background
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              layout="total, sizes,prev, pager, next,jumper"
              :current-page.sync="listQuery.pageNum"
              :page-size="listQuery.pageSize"
              :page-sizes="[10,15,20]"
              :total="count">
      </el-pagination>
    </div>

  </div>
</template>
<script>
  import {getOrderUsersList,supplierList,otherEntryList} from '@/api/partner'
  import {formatDate} from '@/utils/date';
  import store from '@/store'
  import { mapGetters } from 'vuex'
  const defaultListQuery={
    pageNum: 1,
    pageSize: 10,
    billType: '',
    entrySn:null,
    userId:'',
    createTime:null,
    isFreightSettled:null,
  };
  export default {
    name: "index",
    data(){
      return {
        listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
        tableData: [],
        count: 0,
        listLoading: false,
        roles:store.getters.roles ? store.getters.roles : [],
        userOptionList:[],
        options2:[],
      }
    },
    computed: {
      ...mapGetters([
        'name',
        'mobile',
        'userId'
      ]),

    },
    created() {
      this.getList();
      this.getUserOptionList();
      this.getSupplierList();
    },
    filters: {
      formatCreateTime(time) {
        if(time){
          let date = new Date(time);
          return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
        }else{
          return '--'
        }
      },
    },
    methods:{
      //查看发货单
      toDetail(item){
        let routeData = this.$router.resolve({name:'otherInWarehouseDetail',query:{id:item.entryId}});
        window.open(routeData.href);
      },
      //供应商
      getSupplierList() {
        supplierList().then((res)=>{
          this.options2 = res;
        })
      },


      //获取员工下拉选项
      getUserOptionList(){
        getOrderUsersList().then((res)=>{
          this.userOptionList = res;
        })
      },

      //选择员工名称
      handleSelectUserName(key,item){
        this.listQuery[key] = item.userId;
      },


      handleSizeChange(val){
        this.listQuery.pageNum = 1;
        this.listQuery.pageSize = val;
        this.getList();
      },
      handleCurrentChange(val){
        this.listQuery.pageNum = val;
        this.getList();
      },

      handleSearchList(){
        this.listQuery.pageNum = 1;
        this.getList();
      },

      //获取发货明细列表
      getList() {
        this.listLoading = true;
        otherEntryList(this.listQuery).then(response => {
          this.tableData = response.list;
          this.count = response.count;
          this.listLoading = false;
        }).catch(()=>{
          this.listLoading = false;
        });
      },

    },
  }
</script>

<style scoped lang="scss">
  .upload-div{
    text-align: center;
    position:relative;
    #upload{

      opacity: 0;
      position: absolute;
      z-index: 1;
      width:154px;
      height:40px
    }
  }
</style>
